/**********************************************************************
 * Filename: Campeonato.java
 * Created: 2012/04/30
 * @author Fernando Brito e Abreu
 **********************************************************************/
package org.quasar.CopaPaises.businessLayer;

import java.util.Set;
import java.util.HashSet;

public class Campeonato {
	public static Set<Campeonato> allInstances = new HashSet<Campeonato>();

	private TipoCampeonato genero;
	private String nome;

	/**********************************************************************
	 * Default constructor
	 **********************************************************************/
	public Campeonato() {
		allInstances.add(this);
	}

	/**********************************************************************
	 * Parameterized constructor
	 * 
	 * @param genero
	 *            the genero to initialize
	 * @param nome
	 *            the nome to initialize
	 **********************************************************************/
	public Campeonato(TipoCampeonato genero, String nome) {
		this.genero = genero;
		this.nome = nome;
		allInstances.add(this);
	}

	/**********************************************************************
	 * Standard attribute getter
	 * 
	 * @return the genero of the campeonato
	 **********************************************************************/
	public TipoCampeonato getGenero() {
		return genero;
	}

	/**********************************************************************
	 * Standard attribute setter
	 * 
	 * @param genero
	 *            the genero to set
	 **********************************************************************/
	public void setGenero(TipoCampeonato genero) {
		this.genero = genero;
	}

	/**********************************************************************
	 * Standard attribute getter
	 * 
	 * @return the nome of the campeonato
	 **********************************************************************/
	public String getNome() {
		return nome;
	}

	/**********************************************************************
	 * Standard attribute setter
	 * 
	 * @param nome
	 *            the nome to set
	 **********************************************************************/
	public void setNome(String nome) {
		this.nome = nome;
	}

	/**********************************************************************
	 * ONE2MANY getter for Campeonato[1] <-> Grupo[*]
	 * 
	 * @return the grupos of the campeonato
	 **********************************************************************/
	public Set<Grupo> grupos() {
		Set<Grupo> result = new HashSet<Grupo>();
		for (Grupo x : Grupo.allInstances)
			if (x.campeonato() == this)
				result.add(x);
		return result;
	}

	/**********************************************************************
	 * ONE2MANY setter for Campeonato[1] <-> Grupo[*]
	 * 
	 * @param grupos
	 *            the grupos to set
	 **********************************************************************/
	public void setGrupos(Set<Grupo> grupos) {
		for (Grupo x : grupos)
			x.setCampeonato(this);
	}

	/**********************************************************************
	 * MEMBER2ASSOCIATIVE getter for Campeonato[*] <-> Participacao[2..*]
	 * 
	 * @return the participacao of the participado
	 **********************************************************************/
	public Set<Participacao> participacao() {
		Set<Participacao> result = new HashSet<Participacao>();
		for (Participacao x : Participacao.allInstances)
			if (x.participado() == this)
				result.add(x);
		return result;
	}

	/**********************************************************************
	 * MEMBER2ASSOCIATIVE setter for Campeonato[*] <-> Participacao[2..*]
	 * 
	 * @param participacao
	 *            the participacao to set
	 **********************************************************************/
	public void setParticipacao(Set<Participacao> participacao) {
		for (Participacao x : participacao)
			x.setParticipado(this);
	}

	/**********************************************************************
	 * MEMBER2MEMBER getter for Campeonato[*] <-> Pais[2..*]
	 * 
	 * @return the participante of the participado
	 **********************************************************************/
	public Set<Pais> participante() {
		Set<Pais> result = new HashSet<Pais>();
		for (Participacao x : Participacao.allInstances)
			if (x.participado() == this)
				result.add(x.participante());
		return result;
	}

	/**********************************************************************
	 * MEMBER2MEMBER setter for Campeonato[*] <-> Pais[2..*]
	 * 
	 * @param participante
	 *            the participante to set
	 **********************************************************************/
	public void setParticipante(Set<Pais> participante) {
		for (Pais t : participante)
			for (Participacao x : Participacao.allInstances)
				if (x.participado() == this)
					x.setParticipante(t);
	}

	/**********************************************************************
	 * User-defined operation specified in SOIL/OCL
	 **********************************************************************/
	public void criaMembrosEquipas() {

	}

	/**********************************************************************
	 * User-defined operation specified in SOIL/OCL
	 * 
	 * @param nome
	 *            the nome to set
	 * @param genero
	 *            the genero to set
	 * @param paises
	 *            the paises to set
	 * @param grupos
	 *            the grupos to set
	 **********************************************************************/
	public void inicializa(String nome, TipoCampeonato genero, String paises,
			String grupos) {

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	/**********************************************************************
	 * Object serializer
	 **********************************************************************/
	public String toString() {
		return "Campeonato [genero=" + genero + ", nome=" + nome + "]\n";
	}

}
